package com.jz.main.io.nio;

public class VolatileExample {
    int x = 0;
    volatile boolean v = false;

    public void writer() {
        x = 42;      // 步骤1
        v = true;    // 步骤2
    }

    public void reader() {
        if (v) {      // 步骤3
            // 步骤4
            System.out.println(x); // 步骤5
        }
    }

    public static void main(String[] args) {
        VolatileExample a = new VolatileExample();
                a.writer();
                a.reader();
    }
}